<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    
    <form id="DataForm" action="" method="POST" class="layui-form layui-form-pane">
        <div class="layui-tab layui-tab-brief" lay-filter="itemTab">

            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">

                  

                    <div class="layui-form-item">
                        <label class="layui-form-label">生产商</label>
                        <div class="layui-input-block">
                            <input type="text" placeholder="请选择生产商" autocomplete="off" class="layui-input"
                                id="agent_select" value="">
                            <input type="hidden" autocomplete="off" class="layui-input" id="agent_id"
                                name="info[agent_id]" value="">
                        </div>
                    </div>
                    
                    <div class="layui-form-item">
                        <label class="layui-form-label">平台权限</label>
                        <div class="layui-input-block">
                            {foreach $auth as $vo}
                                <input type="checkbox" name="info[auth_id][]" title="{$vo.title}" value="{$vo.id}">
                            {/foreach}
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">结束时间</label>
                        <div class="layui-input-inline">
                            <input type="text" name="info[endtime]" id="date" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-input-inline">
                           
                            <input type="checkbox" name="info[is_endtime]" lay-skin="primary" title="长期" value="1">
                        </div>
                  
                    </div>
                  
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin:auto;text-align: center;">
                            <button id="saveButton" type="submit" class="layui-btn"><i class="fa fa-check"></i>
                                提交</button>
                            <button id="closeButton" type="button" class="layui-btn layui-btn-primary"><i
                                    class="fa fa-close"></i>
                                关闭</button>
                        </div>
                    </div>
                </div>

              

            </div>
        </div>
    </form>
</div>
<script src="/static/admin/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/static/admin/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
      layui.use(['layer', 'form', 'laydate', 'element', 'upload','tableSelect','wangEditor'], function () {
        var    tableSelect = layui.tableSelect;
        var $ = layui.$, layer = layui.layer, table = layui.table,  element = layui.element,laydate = layui.laydate, form = layui.form, upload = layui.upload;
        var indexFrame = parent.layer.getFrameIndex(window.name); //获取窗口索引
        laydate.render({
            elem: '#date'
        });
        $("#saveButton").on('click', function () {
            var loading = layer.open({ type: 3 });
            var data = $("#DataForm").serialize()

            $.ajax({
                url: "{:url('add')}",
                type: 'post',
                data:data,
                success: function (data) {
                    console.log(data);
                    layer.close(loading);
                    if (data.code == 0) {
                        parent.tableReload();
                        parent.layer.close(indexFrame);
                        parent.layer.msg(data.msg);
                    } else {
                        layer.msg(data.msg);
                    }
                }
            })
            return false;
        })
        upload.render({
                elem: '#upload_image', url: "{:url('common/images')}", done: function (res) {
                        $("#image").val(res.data.name);
                        layer.msg(res.msg);
                }
        });
        $("#closeButton").on('click', function () {
            parent.layer.close(indexFrame);
        })
        tableSelect.render({
                elem: '#agent_select',
                checkedKey: 'id',
                searchKey: 'title',
                table: {
                    url: '/admin/agent.index/list',
                    cols: [[
                        { type: 'radio' },
                        { field: 'id', title: 'ID' },
                        { field: 'title', title: '品牌' },
                    ]]
                },
                done: function (elem, data) {
                    var idArr = []
                    var title = []
                    layui.each(data.data, function (index, item) {
                        title.push(item.title)
                        idArr.push(item.id);
                    })
                    $("#agent_id").val(idArr.join(","));
            
                    $("#agent_select").val(title.join(","));
                }
            })
     
            });
</script>
</body>
</html>